package com.opoc.config;

import com.opoc.Interceptor.GlobalInterceptor;
import com.opoc.utils.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @program: opoc
 * @description:
 * @author: lyx
 * @create: 2023-10-25 21:33
 */

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private GlobalInterceptor globalInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("file:"+ FileUtils.ROOT_FILE_PATH);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(globalInterceptor).addPathPatterns("/**")
          .excludePathPatterns("/admin/login")
          .excludePathPatterns("/images/**")
          .excludePathPatterns("/files/**");
    }
}

